package com.ruoyi.nuclein.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.nuclein.domain.MissionOvertime;
import com.ruoyi.nuclein.service.IMissionOvertimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 核酸任务超时Controller
 * 
 * @author ruoyi
 * @date 2023-04-14
 */
@RestController
@RequestMapping("/missionovertime")
public class MissionOvertimeController extends BaseController{
    @Autowired
    private IMissionOvertimeService missionOvertimeService;

    /**
     * 查询核酸任务超时列表
     */
    @RequiresPermissions("nuclein:missionovertime:list")
    @GetMapping("/list")
    public TableDataInfo list(MissionOvertime missionOvertime)
    {
        startPage();
        List<MissionOvertime> list = missionOvertimeService.selectMissionOvertimeList(missionOvertime);
        return getDataTable(list);
    }

    /**
     * 导出核酸任务超时列表
     */
    @RequiresPermissions("nuclein:missionovertime:export")
    @Log(title = "核酸任务超时", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MissionOvertime missionOvertime)
    {
        List<MissionOvertime> list = missionOvertimeService.selectMissionOvertimeList(missionOvertime);
        ExcelUtil<MissionOvertime> util = new ExcelUtil<MissionOvertime>(MissionOvertime.class);
        util.exportExcel(response, list, "核酸任务超时数据");
    }

    /**
     * 获取核酸任务超时详细信息
     */
    @RequiresPermissions("nuclein:missionovertime:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(missionOvertimeService.selectMissionOvertimeById(id));
    }

    /**
     * 新增核酸任务超时
     */
    @RequiresPermissions("nuclein:missionovertime:add")
    @Log(title = "核酸任务超时", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MissionOvertime missionOvertime)
    {
        return toAjax(missionOvertimeService.insertMissionOvertime(missionOvertime));
    }

    /**
     * 修改核酸任务超时
     */
    @RequiresPermissions("nuclein:missionovertime:edit")
    @Log(title = "核酸任务超时", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MissionOvertime missionOvertime)
    {
        return toAjax(missionOvertimeService.updateMissionOvertime(missionOvertime));
    }

    /**
     * 删除核酸任务超时
     */
    @RequiresPermissions("nuclein:missionovertime:remove")
    @Log(title = "核酸任务超时", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(missionOvertimeService.deleteMissionOvertimeByIds(ids));
    }

    /**
     *  定时任务之核酸超时接口
     */
    @PutMapping("/overtime")
    public AjaxResult overtime(){
        return toAjax(missionOvertimeService.overtime());
    }
}
